/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Responses;

import Utilities.ApplicationException;
import Utilities.ExceptionMessages;
import com.sun.xml.ws.commons.virtualbox_3_2.IProgress;
import java.util.ArrayList;

/**
 * Instances of this class are used when returning a response to a virtual medium
 * management request.
 *
 * @author Angel Sanadinov
 */
public class MediumManagementResponse extends ResponseBean
{
    private IProgress operationProgress; //progress object for asynchronous operations
    private String mediumId;             //id of the medium associated with the request/response
    ArrayList<ApplicationException> exceptions;//request exceptions

    /**
     * No-argument constructor.
     *
     * @see ResponseBean#ResponseBean()
     */
    public MediumManagementResponse()
    {
        this.operationProgress = null;
        this.mediumId = null;
        this.exceptions = null;
    }

    /**
     * Constructs the response object using the supplied data.
     *
     * @param requestResult the result of the request. Set to <code>true</code> for
     *                      success or to <code>false</code> for failure
     * @param exception an exception that occurred during request processing
     */
    public MediumManagementResponse(boolean requestResult, ApplicationException exception)
    {
        super(requestResult, exception);
        this.operationProgress = null;
        this.exceptions = null;
    }

    /**
     * Constructs the response object using the supplied data.
     *
     * @param requestResult the result of the request. Set to <code>true</code> for
     *                      success or to <code>false</code> for failure
     * @param operationProgress operation progress object for asynchronous operations
     */
    public MediumManagementResponse(boolean requestResult, IProgress operationProgress)
    {
        super(requestResult, null);
        this.operationProgress = operationProgress;
        this.exceptions = null;
    }

    /**
     * Constructs the response object using the supplied data.
     *
     * @param requestResult the result of the request. Set to <code>true</code> for
     *                      success or to <code>false</code> for failure
     * @param exception an exception that occurred during request processing, if applicable
     * @param operationProgress operation progress object for asynchronous operations
     */
    public MediumManagementResponse(boolean requestResult, ApplicationException exception,
                                    IProgress operationProgress)
    {
        super(requestResult, exception);
        this.operationProgress = operationProgress;
        this.exceptions = null;
    }

    /**
     * Constructs the response object using the supplied data.
     *
     * @param requestResult the result of the request. Set to <code>true</code> for
     *                      success or to <code>false</code> for failure
     * @param exception an exception that occurred during request processing, if applicable
     * @param operationProgress operation progress object for asynchronous operations
     * @param mediumId the UUID of the medium associated with the request/response
     */
    public MediumManagementResponse(boolean requestResult, ApplicationException exception,
                                    IProgress operationProgress, String mediumId)
    {
        super(requestResult, exception);
        this.operationProgress = operationProgress;
        this.mediumId = mediumId;
        this.exceptions = null;
    }

    /**
     * Constructs the response object using the supplied data.
     *
     * @param exceptions a list of exceptions that occurred during request processing
     */
    public MediumManagementResponse(ArrayList<ApplicationException> exceptions)
    {
        super(false, new ApplicationException(ExceptionMessages.APP_E_MULTIPLE_EXCEPTIONS));
        this.operationProgress = null;
        this.mediumId = null;
        this.exceptions = exceptions;
    }

    /**
     * Retrieves the operation progress object.
     *
     * @return the progress object, if available or <code>null</code> otherwise
     */
    public IProgress getProgress()
    {
        return operationProgress;
    }

    /**
     * Retrieves the UUID of the medium associated with the request/response.
     *
     * @return the UUID of the medium, or <code>null</code> if a UUID is not available
     */
    public String getMediumId()
    {
        return mediumId;
    }

    /**
     * Retrieves the list of exceptions that occurred during processing.
     *
     * @return the list of exceptions or <code>null</code> if it is not available
     */
    @Override
    public ArrayList<ApplicationException> getExceptions()
    {
        return exceptions;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (super.toString)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return MediumManagementResponse.class.getSimpleName() + ": (" + super.toString() + ")";
    }
}
